package src.levels 
{
	import flash.display.MovieClip;
	import flash.geom.Rectangle;
	import src.tiles.GroundTile;
	import src.tiles.Tile;
	import src.tiles.WaterTile;
	/**
	 * ...
	 * @author Morozov
	 */
	public class BaseLevel extends MovieClip
	{
		//public var WorldSize:Rectangle;
		public var levelStructure: Array;
		public var levelWidth : Number;
		public var levelHeight: Number;
		public var tileSize:Number = 32;
		
		public function BaseLevel() 
		{
			levelStructure = new Array();
			createWorld();
			levelWidth = levelStructure[0].length;
			levelHeight = levelStructure.length;
			trace("Drawing tiles");
			drawTiles();
			trace("Tiles drawed!");
		}
		
		private function drawTiles():void 
		{
			var i:int;
			var j:int;
			var tile:Tile;
			
			for (i = 0; i < levelHeight; i ++)
			{
				for (j = 0; j < levelWidth; j ++)
				{
					if (levelStructure[i][j] == 1)
					{
						tile = new GroundTile(tileSize, j, i);
						this.addChild(tile);
					}
				}
			}
		}
		private function createWorld()
		{
			//Now it's test function, it will not generate the whole world, but...
			levelStructure[0] =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[1] =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[2] =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[3] =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[4] =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[5] =  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[6] =  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[7] =  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[8] =  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[9] =  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
			levelStructure[10] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
			levelStructure[11] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
		}
	}

}